/*	kd:
	Here you find everything about the base shops: Items, their handlers and
	shops, as well as unlockables. */

// This is what you edit for items and stuff.

class Gcs_BaseShop : Thinker {
	protected Gcs_BaseShopPack		shops;
	protected Gcs_ShopList			shop_list;
	protected Gcs_ShopList			active_shop_list;
	protected Gcs_BaseItemTypes		types;
	
	// Instantiate shop containers:
	protected void ChenLovesSmarties () {
		types				= new("Gcs_BaseItemTypes");
		shops				= new("Gcs_BaseShopPack");
		shop_list			= new("Gcs_ShopList");
		active_shop_list	= new("Gcs_ShopList");
		
		types.Init();
		shops.Init();
		
		shops.spells_i		= shop_list.Push(shops.spells);
		shops.strats_i		= shop_list.Push(shops.strats);
		shops.normal_i		= shop_list.Push(shops.normal);
		shops.special_i		= shop_list.Push(shops.special);
		
		// shop_list.SetPreferenceCvar(
			// "gc_shop_opening",
			// "gc_shop_lastclosed",
			// "gc_shop_openlast");
	}
	
	// Fill the shops in:
	protected void ChenzHouse () {
		
		/*
		
		And here you stuff new items into them. You pass:
		
		1. The inventory class
		2. The handler class INSTANCE
		3. The cost
		4. And maybe how much is sold (= 1 by default)
		
		
		
		Phantasmagoria of Awesomesauce Item Handler Quick Guide
		-------------------------------------------------------
		
		Inventory: Stuff like counters you cannot really use, like the Wing
		Boosters and such.
		
		Ammo: Like inventory, but it accounts for backpacks and skill factors.
		
		Artefact: An inventory that gets placed in your inventory bar and can
		be activated, or equipped and de-equipped.
		
		Armor: This will compare your current armour to all armours available
		in the shop, and it'll notify you if your armour is better, or the same
		as you're currently wearing.
		
		Powerup: Stuff like damage boost spheres that run on a timer. You
		can only buy them again when the power has run out at least 50%.
		
		Stack Powerup: Same as before, but you can buy as many as you like, and
		the power duration will be added on top.
		
		Weapon, Spell, Stratocaster: bb u know it
		
		Toggler: Just like Stratocaster, but it doesn't have the cyan lamps!
		
		*/
		
		// Shopkeepers are merely a suggestion. The player can set a cvar to
		// spawn their favourite (if available).
		// shops.spells	.SuggestShopkeeper('Gcs_Nithor');
		// shops.special	.SuggestShopkeeper('Gcs_Nithor');
		// shops.strats	.SuggestShopkeeper('Gcs_Nithor');
		// shops.normal	.SuggestShopkeeper('Gcs_Nithor');
		
		shops.spells.SetNameLang("spells_shop");
		shops.strats.SetNameLang("strats_shop");
		shops.normal.SetNameLang("normal_shop");
		shops.special.SetNameLang("special_shop");
		
		// ITEMZ:
		shops.spells.AddForSale('SkullfireTome',	types.spell, 1000);
		shops.spells.AddForSale('FrostbiteTome',	types.spell, 1800);
		shops.spells.AddForSale('SkypunchTome',		types.spell, 1500);
		shops.spells.AddForSale('GumpopTome',		types.spell, 800);
		shops.spells.AddForSale('CrowsTome',		types.spell, 2000);
		shops.spells.AddForSale('ThunderTome',		types.spell, 1500);
		shops.spells.AddForSale('BreathTome',		types.spell, 4000);
		shops.spells.AddForSale('CorpseTome',		types.spell, 2000);
		shops.spells.AddForSale('ThreadcutterTome',	types.spell, 1500);
		shops.spells.AddForSale('AnnihilationTome',	types.spell, 8000);
		shops.spells.AddForSale('FirebreathTome',	types.spell, 600);
		shops.spells.AddForSale('MeteorfistTome',	types.spell, 7000);
		shops.spells.AddForSale('FlamewaveTome',	types.spell, 3000);
		shops.spells.AddForSale('ChillgraspTome',	types.spell, 8000);
		shops.spells.AddForSale('SheepshieldTome',	types.spell, 10000);
		shops.spells.AddForSale('SpiritcannonTome',	types.spell, 2400);
		shops.spells.AddForSale('PrismTome',		types.spell, 20000);
		shops.spells.AddForSale('ApocalypseTome',	types.spell, 10000);
		shops.spells.AddForSale('DarkpathTome',		types.spell, 2000);
		// shops.spells.AddForSale('DragonshoutTome',	types.spell, 14000);
		shops.spells.AddForSale('HammersmiteTome',	types.spell, 8000);
		
		shops.strats.AddForSale('BrimstoneStrat',	types.strat, 5000);
		shops.strats.AddForSale('LonghornStrat',	types.strat, 4000);
		shops.strats.AddForSale('StruckerStrat',	types.strat, 3000);
		shops.strats.AddForSale('IronblastStrat',	types.strat, 6000);
		shops.strats.AddForSale('PulverizerStrat',	types.strat, 3000);
		shops.strats.AddForSale('MatriarchStrat',	types.strat, 5000);
		shops.strats.AddForSale('AugurStrat',		types.strat, 8000);
		shops.strats.AddForSale('OldDreadfulStrat',	types.strat, 32167,
			particle_fx: "Gc_Spart_Dreadful");
		shops.strats.AddForSale('DynamiteStrat',	types.strat, 6000);
		
		shops.special.AddForSale('AlchemyLab',		types.inventory,	6000);
		shops.special.AddForSale('GladiusBarrel',	types.inventory,	6000);
		shops.special.AddForSale('MastersOfPain',	types.inventory,	10000);
		shops.special.AddForSale('TibCore',			types.inventory,	8000,
			particle_fx: "Gc_Spart_Dreadful");
		shops.special.AddForSale('ArbiterModule',	types.artefact,		12000,
			particle_fx: "Gc_Spart_Dreadful");
		shops.special.AddForSale('SplitterShield',	types.inventory,	8000);
		
		shops.normal.AddForSale('Medbag',			types.artefact,		800,	100);
		shops.normal.AddForSale('CombatVest',		types.expandarmor,	400);
		shops.normal.AddForSale('CombatArmor',		types.expandarmor,	500);
		shops.normal.AddForSale('AssaultArmor',		types.expandarmor,	800);
		shops.normal.AddForSale('TankArmor',		types.expandarmor,	1600);
		shops.normal.AddForSale('ExtremeSphere',	types.stackpowerup,	20000);
		shops.normal.AddForSale('EnviroSuit',		types.artefact,		400,	100);
		shops.normal.AddForSale('PowerSurge',		types.inventory,	4000);
		shops.normal.AddForSale('PowerBooster',		types.inventory,	1500);
		shops.normal.AddForSale('PowerStimulant',	types.inventory,	3000);
		shops.normal.AddForSale('TNTAmmo',			types.ammo,			200);
		shops.normal.AddForSale('WyvernIdol',		types.artefact,		2000);
		shops.normal.AddForSale('TiberiumBomb',		types.inventory,	600);
		
		let sigil_price = 6000;
		
		switch(gameinfo.gametype) {
		default:
		case GAME_DOOM:
		case GAME_STRIFE:
			shops.normal.AddForSale('PowerLifter',	types.inventory,	1000);
			shops.normal.AddForSale('Amplifier',	types.artefact,		600);
			shops.normal.AddForSale('Gunzerk',		types.artefact,		1500);
			shops.normal.AddForSale('Berserk2',		types.artefact,		1500);
			
			// kd: In case we decide to let you have the sigil like anywhere.
			if(gameinfo.gametype == GAME_STRIFE) {
				sigil_price = 1000000;
			}
			
			break;
		case GAME_HERETIC:
			shops.normal.AddForSale('Ironblast',	types.weapon,	3000);
			shops.normal.AddForSale('TiberiumAmmo',	types.ammo,		300);
			// Fall-through intentional, so Heretic has everything Hexen has!
		case GAME_HEXEN:
			shops.normal.AddForSale('WingsOfWrath',	types.inventory,1000);
			shops.normal.AddForSale('TomeOfPowah',	types.artefact,	600);
			shops.normal.AddForSale('GunzerkPot',	types.artefact,	1500);
			shops.normal.AddForSale('BerserkPot',	types.artefact,	1500);
			break;
		}
		
		// kd: and we did lol
		shops.spells.AddForSale("SigilTome",	types.bigspell,		sigil_price);
		
		// kd: And the secret stars...
		shops.special.AddForSale("VoidwalkersTouch",	types.artefact,	20000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("PhilosophersTome",	types.artefact,	8000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.spells.AddForSale("DragonshoutTome",		types.spell,	14000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("ManaShieldTome",		types.artefact,	10000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("CroesusBlessing",		types.inventory, 6000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("TravelersJournal",	types.Inventory, 5000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("HeavyDutyStompers",	types.Inventory, 5000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("CarnageCollector",	types.Inventory, 6000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("SupermagJohnson",		types.Inventory, 10000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("SupermagTheta",		types.Inventory, 14000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("StridersLantern",		types.artefact,	14000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("PowersuitItem",		types.artefact,	40000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("DraughTome",			types.artefact,	40000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
		shops.special.AddForSale("PowerAutoCannon",		types.artefact,	12000,
			is_secret: true, particle_fx: "Gc_Spart_NewItem");
	}
	
	// kd: Few months later I kinda changed everything again! But I have secret
	// of win, so zhs doesn't have to mess with anything on his side again.
	enum unlockables {
		voidwalkerstouch = 0,
		philosopherstome,
		dragonshout,
		manashield,
		croesusblessing,
		travelersjournal,
		heavydutystompers,
		carnagecollector,
		supermagjohnson,
		supermagtheta,
		striderslantern,
		powersuit,
		draughtome,
		//deadmakermask,
		powerautocannon,
		sigil,
		
		unlock_size	// kd: If you keep this last it'll always be the item count.
	}
	
	protected bool unlocked [unlock_size];
	
	Gcs_ShopList ShopList () const {
		return shop_list;
	}
	
	Gcs_ShopList ActiveShopList () const {
		return active_shop_list;
	}
	
	Gcs_BaseShopPack ShopPack () const {
		return shops;
	}
	
	Gcs_BaseItemTypes ItemTypes () const {
		return types;
	}
	
	static Gcs_BaseShop Find () {
		let iterator = ThinkerIterator.Create("Gcs_BaseShop", stat_static);
		return Gcs_BaseShop(iterator.next());
	}
	
	static void UnlockAll () {
		let handler = Find();
		
		if(handler) {
			handler.MimaLovesCompleteDarkness();
		}
	}
	
	protected void MimaLovesCompleteDarkness () {
		console.printf("\c[fire]All items unlocked!");
		
		for(let i = 0; i < shop_list.ShopCount(); i++) {
			let shop = shop_list.At(i);
			
			for(let j = 0; j < shop.ItemCount(); j++) {
				shop.Unlock(j);
			}
		}
		
		ViveLaReincarnation();
	}
	
	static void Unlock (class <Inventory> inv_class) {
		let handler = Find();
		
		if(handler) {
			handler.OrinLovesHell(inv_class);
		}
	}
	
	protected void OrinLovesHell (class <Inventory> inv_class) {
		Gc_Shop_Inv	shop;
		int			item_i;
		
		[shop, item_i] = shop_list.FindInventory(inv_class);
		
		if(shop && 0 <= item_i && shop.IsHidden(item_i)) {
			shop.Unlock(item_i);
			Console.printf(
				"\c[fire]%s \c[ice]is now available in the \c[fire]%s shop!",
				GetDefaultByType(inv_class).GetTag(),
				shop.ShopName());
		}
		
		ViveLaReincarnation();
	}
	
	protected void ViveLaReincarnation () {
		active_shop_list.CopyWithoutHiddenItems(shop_list);
	}
	
	void ForceActiveShopListUpdate () {
		ViveLaReincarnation();
	}
	
	override void PostBeginPlay () {
		ChangeStatNum(stat_static);
		
		ChenLovesSmarties();
		ChenzHouse();
		ViveLaReincarnation();
	}
}

class Gcs_BaseItemTypes : Gcs_ItemTypePack {
	// Basic handler instances.
	Gcs_ItemType	weapon;
	Gcs_ItemType	inventory;
	Gcs_ItemType	spell;
	Gcs_ItemType	strat;
	Gcs_ItemType	permastrat;
	Gcs_ItemType	bigspell;
	Gcs_ItemType	toggler;
	Gcs_ItemType	ammo;
	Gcs_ItemType	powerup;
	Gcs_ItemType	armor;
	Gcs_ItemType	expandarmor;
	Gcs_ItemType	artefact;
	Gcs_ItemType	stackpowerup;
	// Gcs_ItemType     invtoggler;
	
	override void Init () {
		if(is_init) {
			return;
		}
		
		weapon			= InstType("Gcs_ItWeapon");
		inventory		= InstType("Gcs_ItInventory");
		spell			= InstType("Gcs_ItSpell");
		bigspell		= InstType("Gcs_ItBigSpell");
		strat			= InstType("Gcs_ItStrat");
		permastrat		= InstType("Gcs_ItPermaStrat");
		toggler			= InstType("Gcs_ItToggler");
		ammo			= InstType("Gcs_ItAmmo");
		powerup			= InstType("Gcs_ItPowerup");
		armor			= InstType("Gcs_ItArmor");
		expandarmor		= InstType("Gcs_ItExpandArmor");
		artefact		= InstType("Gcs_ItArtefact");
		stackpowerup	= InstType("Gcs_ItStackPowerup");
		// invtoggler      = InstType("Gcs_ItInvToggler");
		
		is_init = true;
	}
}

class Gcs_BaseShopPack : Gcs_ShopPack {
	Gc_Shop_Inv    spells;
	Gc_Shop_Inv    strats;
	Gc_Shop_Inv    normal;
	Gc_Shop_Inv    special;
	
	uint           spells_i;
	uint           strats_i;
	uint           normal_i;
	uint           special_i;
	
	override void Init () {
		if(is_init) {
			return;
		}
		
		spells	= new("Gc_Shop_Inv");
		strats	= new("Gc_Shop_Inv");
		normal	= new("Gc_Shop_Inv");
		special	= new("Gc_Shop_Inv");
		
		is_init = true;
	}
}